<?php
session_start();
include("../inc/config.php");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Azeroth-Gaming - ACP</title>

<!-- CSS -->
<link href="style/css/transdmin.css" rel="stylesheet" type="text/css" media="screen" />
<!--[if IE 6]><link rel="stylesheet" type="text/css" media="screen" href="style/css/ie6.css" /><![endif]-->
<!--[if IE 7]><link rel="stylesheet" type="text/css" media="screen" href="style/css/ie7.css" /><![endif]-->

<!-- JavaScripts-->
<script type="text/javascript" src="style/js/jquery.js"></script>
<script type="text/javascript" src="style/js/jNice.js"></script>
</head>

<body>
<?php
if(!isset($_SESSION['username']))
{
echo "<META http-equiv='refresh' content='1; URL=log.php'>";
die();
}
else{
?>
	<div id="wrapper">
    	<!-- h1 tag stays for the logo, you can use the a tag for linking the index page -->
    	<h1><a href="#"><span>Transdmin Light</span></a></h1>
        
        <!-- You can name the links with lowercase, they will be transformed to uppercase by CSS, we prefered to name them with uppercase to have the same effect with disabled stylesheet -->
        <ul id="mainNav">
        	<li><a href="index.php" class="active">Main</a></li> <!-- Use the "active" class for the active menu item  -->
        	<li><a href="profile.php">Admin Panel</a></li>
        	<li class="logout"><a href="logout.php">LOGOUT</a></li>
			<li class="logout"><a href="#"><?php print("Welcome <font color='#FFC100'>".$_SESSION['username']."</font>");?></li>
        </ul>
        <!-- // #end mainNav -->
        
        <div id="containerHolder">
			<div id="container">
        		<div id="sidebar">
                	<ul class="sideNav">
                    	<li><a href="#" class="active">News</a></li>
                    </ul>
                    <!-- // .sideNav -->
                </div>    
                <!-- // #sidebar -->
                
                <!-- h2 stays for breadcrumbs -->
                <h2><a href="#">Main</a> &raquo; <a href="#" class="active">News</a></h2>
                
                <div id="main">
					<h3>Add New</h3>
                    	<fieldset>
						<form method="get" name="submit" class="jNice">
                        	<p><label>Title:</label><input type="text" name="title" class="text-long" /></p>
                        	<p><label>Date:</label><input type="text" name="date" class="text-medium" /></p>
                            <p><label>Poster:</label><input type="text" name="poster" class="text-medium" />
                            </p>
                        	<p><label>New:</label><textarea name="news" rows="3" cols="40"></textarea></p>
                            <input type="submit" name="submit" value="Submit New" />
						</form>
<?php	
mysql_select_db($cmsdb, $conn) OR die("Error: ".mysql_error());

if(isset($_GET['submit']))
{					
$title="$_GET[title]";
$date="$_GET[date]";
$news="$_GET[news]";
$poster="$_GET[poster]";
$errors = array();

                if(!$title) {
            $errors[] = "Enter the news title!";
        }
		        if(!$date) {
            $errors[] = "Enter the date of the news!";
        }
				if(!$news) {
            $errors[] = "Please enter a new!";
        }
				if(!$poster) {
            $errors[] = "Please tell me who is the writer!";
        }
		

        if(count($errors) > 0) {
            foreach($errors AS $error){
                echo "" . $error . "<br>\n";
            }
        }else {
	            $sql4 = "INSERT INTO `news`
                    (`news_title`,`news_date`,`news`,`poster`)
                    VALUES ('$title','$date','$news','$poster')";
            $res4 = mysql_query($sql4) or die(mysql_error());
            echo "Grats you add a new news :D";
        }	
}
?>
                        </fieldset>
						<h3>Remove New</h3>
						<fieldset>
<?php
	echo "
		</br>
		</br>
		<form method=get name=submit class=jNice>ID
		<br />
		<input class='text-medium' type=text name=id>
		<br />
		</br>
		</br>
		<input type='submit' name='submit2' value='Remove New' />
		</form>
		";

if(isset($_GET['submit2']))
{
$id="$_GET[id]";
$errors = array();

                if(!$id) {
            $errors[] = "Enter the news ID!";
        }		

        if(count($errors) > 0) {
            foreach($errors AS $error){
                echo "" . $error . "<br>\n";
            }
        }else {
	            $sql4 = "DELETE FROM news WHERE news_id='$id'";
            $res4 = mysql_query($sql4) or die(mysql_error());
            echo "Grats you remove a new :D";
        }	
}
?>
</fieldset>
<h3>News</h3>
						<fieldset>
						<?php
$sql = "SELECT * FROM news ORDER BY news_id DESC";
$query_news=mysql_query("SELECT * FROM news ORDER BY news_id DESC") or die (mysql_error());

echo "<table align='center' width='600' >
<tr>
<td valign='top'><font size='3' color='6600FF'>ID</font></td>
<td valign='top'><font size='3' color='6600FF'>Title</font></td>
<td valign='top'><font size='3' color='6600FF'>Date</font></td>
<td valign='top'><font size='3' color='6600FF'>News</font></td>
<td valign='top'><font size='3' color='6600FF'>Poster</font></td>
</tr>
";
while($row=mysql_fetch_array($query_news))
{
echo "
<tr>
<td  class=\"alt\">
<p style='padding-left: 5px'>".$row['news_id']."</p>
</td>
<td><p>".$row['news_title']."</p></td>

<td><p>".$row['news_date']."</p></td>
<td><p>".$row['news']."</p></td>
<td><p>".$row['poster']."</p></td>
</tr>";

}
echo "</table>";

echo '</table>';
?>
</fieldset>

                    </form>
                </div>
                <!-- // #main -->
                
                <div class="clear"></div>
            </div>
            <!-- // #container -->
        </div>	
        <!-- // #containerHolder -->
        
        <p id="footer">Azeroth-Gaming ACP</br>Coded By <a href="http://www.perspectived.com">Ac0</a></p>
    </div>
    <!-- // #wrapper -->
	<?php } ?>
</body>
</html>
